<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
  <head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Selenium IDE Test</title>
		<script type="text/javascript" src="chrome://selenium-ide/content/selenium-core/lib/prototype.js"></script>
		<script type="text/javascript" src="chrome://selenium-ide/content/selenium-core/lib/scriptaculous/scriptaculous.js"></script>
		<script type="text/javascript" src="chrome://selenium-ide/content/selenium-core/lib/scriptaculous/unittest.js"></script>
		<script type="text/javascript" src="chrome://selenium-ide/content/preferences.js"></script>
    <script type="text/javascript" src="chrome://selenium-ide/content/selenium-ide-loader.js"></script>
  </head>

  <body>
  <div id="testlog">
  </div>
  <script type="text/javascript">
Test.Unit.Testcase.prototype.waitFor = function(condition, nextPart) {
  this.wait(3000, function() {
    if (condition()) {
      nextPart();
    } else {
      this.waitFor(condition, nextPart);
    }
  });
};

new Test.Unit.Runner({
    setup: function() {
    },
    
    teardown: function() {
    },
    
    testPlay: function() { with(this) {
        var editor = SeleniumIDE.Loader.getTopEditor();
        editor.getOptions().userExtensionsURL = "chrome://selenium-ide/content/tests/functional/TestTestRunner-extension.js";
        var testCase = editor.app.getFormats().getDefaultFormat().loadFile("chrome://selenium-ide/content/tests/functional/TestTestRunner-testcase.html", true);
        editor.app.setTestCaseWithNewSuite(testCase);
        editor.app.setBaseURL("http://www.openqa.org/");
        var testWindow = editor.showInBrowser("about:blank", true);
        var i = 0;
        var noLongerPlaying = function() {
            return editor.selDebugger.state != 1;
        };
        var lastCommand = null;
        // execute each commands individually
        var loop = function() {
            waitFor(noLongerPlaying,
                    function() {
                        if (lastCommand) {
                            assert(!lastCommand.failed);
                        }
                        while (i < editor.getTestCase().commands.length) {
                            var command = editor.app.getTestCase().commands[i++];
                            if ("command" != command.type) continue;
                            editor.selDebugger.executeCommand(command);
                            lastCommand = command;
                            loop();
                            return;
                        }
                        testWindow.close();
                        assert(!editor.getTestCase().debugContext.failed);
                    });
        };
        wait(1000, function() {
            loop();
        });
    }}
});
    </script>
  </body>
</html>
